// A_program.c
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <fcntl.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>

#define FIFO_NAME "my_fifo"
#define FIFO_NAME1 "my_fifo1"

int main(int argc,char *argv[]) {
    int fifo_fd,fifo_fd1;

    // send signel
    // 创建命名管道
    mkfifo(FIFO_NAME, 0666);
    mkfifo(FIFO_NAME1, 0666);

    // 打开管道（写模式）
    fifo_fd = open(FIFO_NAME, O_WRONLY);
    fifo_fd1 = open(FIFO_NAME1, O_WRONLY);

    if (fifo_fd == -1) {
        perror("open");
        exit(1);
    }

    // 向管道写入数据
    size_t ret = write(fifo_fd, argv[1], strlen(argv[1]));
    size_t ret1 = write(fifo_fd1, argv[2], strlen(argv[2]));
    
    if(ret == strlen(argv[1]))
        printf("Program A sent: %s success!\n", argv[1]);
    else{
        printf("fail\n");
        printf("ret = %ld, strlen(argv[1]) = %ld)\n",ret,strlen(argv[1]));
    }
        

    // 关闭管道
    close(fifo_fd);
    close(fifo_fd1);
    // end send signel
    
    return 0;
}
